﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using HungryCrowdLibrary;

namespace HungryCrowdLibrary.Manager
{
    public class UserManager
    {
        #region Save
        public bool SaveChanges(User user)
        {
            var success = false;
            using (var hctx = new HungryCrowdEntities())
            {
                hctx.Users.Add(user);
                success = hctx.SaveChanges() > 0;
            }           

            return success;
        }
        #endregion

        #region Verify User
        public User VerifyPassword(Expression<Func<User, bool>> search)
        {
            var user = new User();
            using (var hctx = new HungryCrowdEntities())
            {
              user = hctx.Users.Where(search).SingleOrDefault();
            }

            return user;
        }

        public string GetSaltForUser(Expression<Func<User, bool>> search)
        {
            var salt = string.Empty;
            using (var hctx = new HungryCrowdEntities())
            {
                salt = hctx.Users.Where(search).SingleOrDefault().Salt;
            }

            return salt;
        }

        #endregion
    }
}
